﻿using CoffeeShop.DAO;
using CoffeeShop.Models.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace CoffeeShop.BIZ
{
    public class CategoryBiz
    {
        private CategoryDao _categoryDao = new CategoryDao();

        /// <summary>
        /// Convert to Category object
        /// </summary>
        /// <param name="categoryId">ID</param>
        /// <param name="categoryName">Name</param>
        /// <param name="isDeleted">IsDeleted</param>
        /// <returns>Category object</returns>
        public Category ConvertToBaseObject(string categoryName, int categoryId = 0, bool isDeleted = false)
        {
            Category categoryEnt = new Category();
            categoryEnt.ID = categoryId;
            categoryEnt.Name = categoryName;
            categoryEnt.IsDeleted = isDeleted;
            return categoryEnt;
        }

        /// <summary>
        /// Get all categories in DB
        /// </summary>
        /// <returns></returns>
        public List<Category> GetListCategories()
        {
            return _categoryDao.GetListCategories();
        }

        /// <summary>
        /// Get a category by CategoryId
        /// </summary>
        /// <param name="categoryId">CategoryId</param>
        /// <returns>True: Successful --- False: Fail</returns>
        public Category GetCategoryById(int categoryId)
        {
            return _categoryDao.GetCategoryById(categoryId);
        }

        /// <summary>
        /// Get a category by name
        /// </summary>
        /// <param name="categoryName"></param>
        /// <returns></returns>
        public Category GetCategoryByName(string categoryName)
        {
            return _categoryDao.GetCategoryByName(categoryName);
        }

        /// <summary>
        /// Create a category
        /// </summary>
        /// <param name="category">Category object</param>
        /// <returns>True: Successful --- False: Fail</returns>
        public bool CreateCategory(Category category)
        {
            return _categoryDao.CreateCategory(category);
        }

        /// <summary>
        /// Update a category
        /// </summary>
        /// <param name="areaId">Category object</param>
        /// <returns>True: Successful --- False: Fail</returns>
        public bool UpdateCategory(Category category)
        {
            return _categoryDao.UpdateCategory(category);
        }

        /// <summary>
        /// Delete a categoy
        /// </summary>
        /// <param name="categoryId">CategoryId</param>
        /// <returns>True: Successful --- False: Fail</returns>
        public bool DeleteCategory(int categoryId)
        {
            return _categoryDao.DeleteCategory(categoryId);
        }

        /// <summary>
        /// Check is existed a category when add new a category
        /// </summary>
        /// <param name="categoryName"></param>
        /// <returns></returns>
        public bool IsExistedCategoryAdd(string categoryName)
        {
            var category = this.GetCategoryByName(categoryName);
            if (category != null)
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// Check is existed a category when update a category
        /// </summary>
        /// <param name="categoryId">Id</param>
        /// <param name="categoryName">Name</param>
        /// <returns>True: Existed -- False: Not existed</returns>
        public bool IsExistedCategoryUpdate(int categoryId, string categoryName)
        {
            return _categoryDao.IsExistedCategoryUpdate(categoryId, categoryName);
        }
    }
}